All Questions
Tagged with programming-practicesobject-oriented-design
38 questions
-1votes
1answer
167views
Help in understanding if my design getting complicated [closed]
I have 3 classes class Backup end class Database end Class App end The backup database has a reference to Database and App, like class Backup def getDatabase Database.create end def ...
2votes
3answers
235views
Correctness of an implementation beyond the methods signature contract of an interface
Is there a programming principle/guideline that tackles the correctness of a implementation beyond the methods signature contract of an interface? Let's say we have a repository interface with two ...
-1votes
1answer
107views
How can I prevent an object from being re-sanitized everytime it is passed as input to a function?
Suppose that I have a class named CharStream Additionally, there are a large number of functions which convert their function input into a CharStream def funky_the_function(_input): input = ...
3votes
4answers
780views
Is it a bad practice to have an interface method to tell whether it can handle an object?
interface Resolver { boolean canResolve(SomeInput input); SomeOutput resolve(SomeInput input); } public static void main(String[] args) { List<Resolver> resolvers = ...; ...
4votes
3answers
1kviews
Passing object or using the field
I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class? Using the field: ...
-1votes
1answer
241views
How to avoid cyclic dependency in UI application
I'm developing an UI application where I ran into an issue with a cyclic dependency. Here is the simplified code, to explain the problem. #include <list> class UiStyle; UiStyle* CreateStyle(); ...
-1votes
3answers
226views
Difference between update a property and fire an event
It seems to me that update a property is always an 'event' and that all you can do with an event handler can be done in the property let/set routine. And, in my limited experience, I never needed to ...
0votes
1answer
564views
Using for_each instead of iterators to avoid iterator invalidation
I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
0votes
2answers
2kviews
Should I use a class with only static members to encapsulate my program?
So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like: //includes type aliases #include "GlobalTypes.h" //main body ...
2votes
1answer
118views
Is it a good software engineering practice to store libraries as attributes of objects?
Suppose I initialize a library, say, in python object - #filename: file_A import file_ class A(): def __init__(self): self.pd = file_.pd self.np = file_.np And suppose the ...
2votes
2answers
4kviews
Module with globals or Class with attributes?
Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
1vote
1answer
618views
Should the function that operates on the object return it?
Should the function that operates on the object return it? Shortened example: class Example1 { public function method($a, $b) { $result = new Result($a, $b); $this->...
2votes
5answers
1kviews
What should a constructor contain?
What should a constructor contain? In both cases, all three arguments are needed for the class to work. Which approach is better and why? 1) class Language { LanguageRepository ...
-6votes
1answer
189views
Finding object relationships [closed]
Description Its a follow up question of writing use cases. Taking from nouns defined in my user story and requirement I found the following candidates to be classes: User Question Session Attempt/...
4votes
4answers
539views
Is it better to generate a large list during the constructor or when it's accessed?
I've got a class member function that generates a large list and puts it into a private member variable so it can be accessed through a getter. The generation of this list is a rather intensive ...